@extends('admin.main')
@section('head')
    @include('UEditor::head')
    <style>
        .upload-button {
            position: relative;
            display: inline-block;
            padding: 4px 12px;
            overflow: hidden;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
            color: #fff;
            background-color: #27ae60;
            text-align: center;
            width: 100px;
        }

        .upload-button input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }

        .upload-img-box .upload-pre-item {
            float: left;
            padding: 0px;
            margin: 1px 10px 1px 1px;
            width: 150px;
            max-height: 180px;
            overflow: hidden;
            text-align: center;
            cursor: pointer;
            border: 1px solid #ccc;
            transition: all .3s linear;
        }

        .upload-pre-item img {
            border-bottom: 1px solid #ccc;
        }

        .upload-pre-item div {
            background-color: lightgrey;
        }
    </style>
@endsection
@section('body')
    <div class="main-title">
        <h2>设置店铺信息</h2>
    </div>
    <div class="tab-wrap">
        <div class="tab-content">
            <form action="" method="post" class="form-horizontal">
                <div id="tab1" class="tab-pane in tab1">
                    <div class="controls" id="shop_logo">
                        <label class="item-label">店铺logo<span class="check-tips">（请上传尺寸为80*80的图片，格式为jpg、png、gif，上传图片大小必须在2M以下）</span></label>
                        <div class="upload-button">
                            <span class="uploadify-button-text">上传图片</span>
                            <input type="file" id="uploadLogo" accept="image/png,image/jpeg,image/gif" num="1"
                                   onchange="upload(this,'shop_logo','logo[]')" count="{{file_exists(public_path('uploads/logos/imgs/'.$info['admin_id'].'/'.$info['id'].'_1.'.$ext)) ? 1 : 0}}"/>
                        </div>
                        <div class="upload-img-box">
                            @if(file_exists(public_path('uploads/logos/imgs/'.$info['admin_id'].'/'.$info['id'].'_1.'.$ext)))
                                <div class="upload-pre-item" id="shop_logo_1">
                                    <img src="/uploads/logos/imgs/{{$info['admin_id']}}/{{$info['id'].'_1'}}.{{$ext}}?{{time()}}"/>
                                    <div class="shop_logo" onclick="delImg('uploadLogo','shop_logo_1')">
                                        删除
                                    </div>
                                    <input type="hidden" name="logo[]" class="logo"
                                           value="/uploads/logos/imgs/{{$info['admin_id']}}/{{$info['id'].'_1'}}.{{$ext}}">
                                </div>
                            @endif
                        </div>
                    </div>
                    <div id="tab1" class="tab-pane in tab1">
                        <div class="controls" id="shop_img">
                            <label class="item-label">店铺图片<span class="check-tips">（请上传尺寸为400*150的图片，格式为jpg、png、gif，上传图片大小必须在2M以下）</span></label>
                            <div class="upload-button">
                                <span class="uploadify-button-text">上传图片</span>
                                <input type="file" id="uploadImage" accept="image/png,image/jpeg,image/gif" num="1"
                                       onchange="upload(this,'shop_img','imgs[]')"
                                       count="{{isset($info) ? $info['pic_num'] : 0}}"/>
                            </div>
                            <div class="upload-img-box">
                                @if(isset($info) && $info['pic_num'])
                                    @for ($i = 1; $i <= $info['pic_num']; $i++)
                                        @if(file_exists(public_path('uploads/shops/imgs/'.$info['admin_id'].'/'.$info['id'].'_'.$i.'.'.$ext)))
                                        <div class="upload-pre-item" id="shop_img_{{$i}}">
                                            <img src="/uploads/shops/imgs/{{$info['admin_id']}}/{{$info['id']}}_{{$i}}.{{$ext}}?{{time()}}"/>
                                            <div class="shop_img_{{$i}}"
                                                 onclick="delImg('uploadImage','shop_img_{{$i}}')">删除
                                            </div>
                                            <input type="hidden" name="imgs[]" class="shop_img_{{$i}}"
                                                   value="/uploads/shops/imgs/{{$info['admin_id']}}/{{$info['id']}}_{{$i}}.{{$ext}}">
                                        </div>
                                        @endif
                                    @endfor
                                @endif
                            </div>
                        </div>
                        @if(plat_identify() === true)
                            <div class="form-item">
                                <label class="item-label">微信支付功能<span class="check-tips"></span></label>
                                <div class="controls">
                                    <label class="radio"><input type="radio" name="online_pay" value="1" @if(isset($info['online_pay']) && $info['online_pay'] == 1) checked  @endif>开启</label>
                                    <label class="radio"><input type="radio" name="online_pay" value="0" @if(!isset($info['online_pay']) ||  $info['online_pay'] == 0) checked  @endif >关闭</label>
                                </div>
                            </div>
                        @endif
                        <div class="form-item">
                            <label class="item-label">货到付款功能<span class="check-tips"></span></label>
                            <div class="controls">
                                <label class="radio"><input type="radio" name="offline_pay" value="1" @if(isset($info['offline_pay']) && $info['offline_pay'] == 1) checked  @endif>开启</label>
                                <label class="radio"><input type="radio" name="offline_pay" value="0" @if(!isset($info['offline_pay']) ||  $info['offline_pay'] == 0) checked  @endif >关闭</label>
                            </div>
                        </div>
                        <div class="form-item">
                            <label class="item-label">
                                营业时间<span class="check-tips">(格式：8：30 —  17：30)</span>
                            </label>
                            <div class="controls">
                                <input type="text" name="work_time" class="text input-large"
                                       value="{{isset($info['work_time']) ? $info['work_time'] : ''}}">
                            </div>
                        </div>
                        <div class="form-item">
                            <label class="item-label">
                                联系方式<span class="check-tips">(店铺联系方式，手机号或座机号)</span>
                            </label>
                            <div class="controls">
                                <input type="text" name="contact" class="text input-large"
                                       value="{{isset($info['contact']) ? $info['contact'] : ''}}">
                            </div>
                        </div>
                        <div class="form-item">
                            <label class="item-label">
                                催单电话<span class="check-tips">(用户催单联系方式，手机号)</span>
                            </label>
                            <div class="controls">
                                <input type="text" name="cd_contact" class="text input-large"
                                       value="{{isset($info['cd_contact']) ? $info['cd_contact'] : ''}}">
                            </div>
                        </div>
                        <div class="form-item">
                            <label class="item-label">催单功能<span class="check-tips"></span></label>
                            <div class="controls">
                                <label class="radio"><input type="radio" name="cui_dan" value="1" @if(isset($info['cui_dan']) && $info['cui_dan'] == 1) checked  @endif>开启</label>
                                <label class="radio"><input type="radio" name="cui_dan" value="0" @if(!isset($info['cui_dan']) ||  $info['cui_dan'] == 0) checked  @endif >关闭</label>
                            </div>
                        </div>
                        <div class="form-item">
                            <label class="item-label">
                                配送范围<span class="check-tips"></span>
                            </label>
                            <div class="controls">
                                <label class="textarea input-large">
                                    <textarea name="send_area"
                                              placeholder="格式：&#13;&#10;1.XXXXXXX&#13;&#10;2.XXXXXXX">{{$info['send_area']}}</textarea>
                                </label>
                            </div>
                        </div>
                        <div class="form-item">
                            <label class="item-label">
                                订水须知<span class="check-tips"></span>
                            </label>
                            <div class="controls">
                                <label class="textarea input-large">
                                    <textarea name="notice"
                                              placeholder="格式：&#13;&#10;1.XXXXXXX&#13;&#10;2.XXXXXXX">{{$info['notice']}}</textarea>
                                </label>
                            </div>
                        </div>
                        <div class="form-item">
                            <label class="item-label">水票须知</label>
                            <div class="controls">
                                <script id="container" name="bill_notice"
                                        type="text/plain">{!! isset($info['bill_notice']) ? $info['bill_notice'] : '' !!}</script>
                                <!-- 实例化编辑器 -->
                                <script type="text/javascript">
                                    var ue = UE.getEditor('container');
                                </script>
                            </div>
                        </div>
                    </div>
                    <!-- 高级 -->
                    <div class="form-item">
                        <input type="hidden" name="id" value="{{$info['id']}}">
                        <input type="hidden" name="shop_id" value="{{$shop_id}}">
                        <input type="hidden" name="admin_id" value="{{$admin_id}}">
                        <button type="submit" id="submit" class="btn submit-btn ajax-post"
                                target-form="form-horizontal">确 定
                        </button>
                        <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
                    </div>
            </form>
        </div>
    </div>
@endsection

@section('script')
    <script type="text/javascript">

        function delImg(upInputId, fileId) {
            var _this = $("#" + upInputId);
            var count = parseInt(_this.attr('count'));
            _this.attr('count', count - 1);
            $("#" + fileId).remove();
        }
        function upload(obj, imgId, name) {
            var _self = obj;
            var _this = $(obj);
            var fileReader = new FileReader();
            fileReader.onload = function (e) {
                if (fileReader.readyState == FileReader.DONE) {
                    var file = _self.files[0];
                    var type = file.type;
                    var size = parseInt(file.size);
                    var allowSize = parseInt(2097152); //限制上传图片大小1M以下,2*1024*1024
                    if (size > allowSize) {
                        layer.msg('上传图片大小必须在2M以下');
                        return false;
                    }
                    var accept = _this.attr('accept');//上传图片数量
                    var param_num = _this.attr('num');//上传图片数量
                    var param_count = _this.attr('count');//已上传图片数量
                    var acceptArr = accept.split(",");
                    if ($.inArray(type, acceptArr) < 0) {
                        layer.msg('请上传' + accept + '等格式的文件');
                        return false;
                    }
                    if (param_num == null || param_num == undefined) {
                        _this.attr('num', 1);
                    }
                    if (param_count == null || param_count == undefined) {
                        _this.attr('count', 0);
                    }
                    var num = parseInt(_this.attr('num'));
                    var count = parseInt(_this.attr('count'));
                    if (count < num) {
                        count = count + 1;
                        var upFileId = _this.attr('id');
                        var fileId = imgId + '_' + count;
                        var func = 'delImg("' + upFileId + '","' + fileId + '")';
                        $("#" + imgId).find('.upload-img-box').append(
                                '<div class="upload-pre-item" id="' + fileId + '"><img src="' + this.result + '"/><div class="' + fileId + '" onclick=' + func + '>删除</div><input type="hidden" name="' + name + '" class="' + fileId + '"  value="' + this.result + '"></div>'
                        );
                        _this.attr('count', count);
                    } else {
                        layer.msg('最多上传' + num + '张');
                        return false;
                    }
                    _self.value = ''; //清空上传成功后的value值
                }
            };
            //一次加载多个文件
            var i = 0, src = _self.files;
            fileReader.readAsDataURL(src[i]);
            fileReader.onloadend = function () {
                i++;
                if (i < src.length) fileReader.readAsDataURL(src[i]);
            }
        }
    </script>
@endsection
